package com.ljz.servlet;

import com.ljz.dao.EmpDao;
import com.ljz.entity.Employ;
import com.ljz.utils.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/editEmp")
public class EditEmpServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Integer eid = Integer.valueOf(req.getParameter("eid"));
        SqlSession sqlSession = SqlSessionFactoryUtil.getSqlSession();
        EmpDao empDao = sqlSession.getMapper(EmpDao.class);
        Employ empById = empDao.findEmpById(eid);
        HttpSession session = req.getSession();
        session.setAttribute("emp", empById);
        resp.getWriter().print("true");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
